/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.biosample.robot.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

/**
 *
 * @author mvs
 */
public class SourceTubeWindow extends JFrame 
        implements ActionListener,MouseListener {

    private static final int NUM_ROWS = 10;
    private static final int NUM_COLS = 5;
    
    private JPanel cp;
    private SourceTubePanel tubePanel;
    private SourceControlPanel controlPanel;
    
    public SourceTubeWindow() {
        this.setSize(new Dimension(600,600));
        //this.setMinimumSize(new Dimension(200,400));
        cp = new JPanel(new GridBagLayout());
        cp.setDoubleBuffered(true);
        GridBagConstraints cpConstraints = new GridBagConstraints();
        this.setContentPane(cp);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
        tubePanel = new SourceTubePanel(NUM_ROWS, NUM_COLS, "Source Tubes");
        tubePanel.addMouseListener(this);
        tubePanel.setVisible(true);
        cpConstraints.fill = GridBagConstraints.BOTH;
        cpConstraints.gridx = 0;
        cpConstraints.gridy = 0;
        cpConstraints.weightx = 1;
        cpConstraints.weighty = 1;
        cpConstraints.insets = new Insets(5,5,5,5);
        cp.add(tubePanel, cpConstraints);
        
        
        /*controlPanel = new SourceControlPanel(this);
        controlPanel.setVisible(true);
        cpConstraints.fill = GridBagConstraints.BOTH;
        cpConstraints.gridx = 1;
        cpConstraints.weightx = 1;
        cp.add(controlPanel, cpConstraints);*/
        
        cp.validate();
        cp.setVisible(true);
        this.validate();
        this.setVisible(true);
        
    }
    
    public void actionPerformed(ActionEvent ae) {
        for(int i = 0; i < NUM_ROWS * NUM_COLS; i++) {
            //tubePanel.tubes[i].setInfo(new SampleInfo("TS00" + i, "BLAH", controlPanel.getCurrentSampleType()));
            //tubePanel.tubes[i].setToolTipText(
            //        tubePanel.tubes[i].toString());
        }
        tubePanel.repaint();
    }
    
    public void mouseEntered(MouseEvent me) {
        
    }
    public void mouseClicked(MouseEvent me) {

    }

    public void mousePressed(MouseEvent me) {
    	System.out.println("click");
        Component clicked = tubePanel.findComponentAt(me.getPoint());
        if(clicked.getClass().equals(SourceTubeIcon.class)) {
            //((SourceTubeIcon)clicked).setInfo(new SampleInfo("TS00", "BLAH", controlPanel.getCurrentSampleType()));
            if(!tubePanel.addSelected((SourceTubeIcon)clicked))
            	tubePanel.delSelected((SourceTubeIcon)clicked);
            tubePanel.repaint();
        }
        //else
            //tubePanel.Selected(null);
            //tubePanel.repaint();
    }

    public void mouseReleased(MouseEvent me) {
    }

    public void mouseExited(MouseEvent me) {

    }
    
    public static void main(String[] args) {
        SourceTubeWindow stw = new SourceTubeWindow();
    }
}
